package com.chinasofti.zbest.service.impl;

import com.chinasofti.zbest.dao.model.User;
import com.chinasofti.zbest.dao.UserMapper;
import com.chinasofti.zbest.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinasofti.zbest.service.info.UserModifyInformationInfo;
import com.chinasofti.zbest.web.form.ModifyUserInformationForm;
import com.chinasofti.zbest.web.form.RegForm;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户 服务实现类
 * </p>
 *
 * @author zbest
 * @since 2019-05-28
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void add(RegForm regForm) {
        User user = new User();
        BeanUtils.copyProperties(regForm, user);
        System.out.println(user);
        userMapper.insert(user);
    }

    @Override
    public User login(String username, String password) {
        return userMapper.findByUsernameAndPassword(username, password);
    }

    @Override
    public void modifypass(String username, String newpassword) {
        userMapper.modifyPassword(username, newpassword);

    }

    @Override
    public void updateUserInformation(UserModifyInformationInfo user) {
        userMapper.updateUserInformation(user.getUserId(), user.getBirthday(), user.getNikeName(), user.getUsername(), user.getUserPhone(), user.getUserSex());
    }


}
